package com.tr.rentcar.model.dao;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.tr.rentcar.model.GlobalParamHandler;
import com.tr.rentcar.model.bean.OrderRecord;
import com.tr.rentcar.model.jdbc.MySqlDb;
import com.tr.rentcar.model.jdbc.ResultHandler;

public class OrderRecordDao implements ResultHandler<OrderRecord>{
	MySqlDb db=MySqlDb.getInstance();

	@Override
	public OrderRecord doHander(Map<String, Object> row) {
		OrderRecord or=new OrderRecord();
		or.setOrId(Integer.parseInt(row.get("or_id")+""));
		or.setOrContent(row.get("or_content")+"");
		or.setOrMan(row.get("or_man")+"");
		or.setOrDate((Date)row.get("or_date"));
		or.setOid(Integer.parseInt(row.get("oid")+""));
		return or;
	}
	
	/**
	 * 根据订单id获取该订单所有操作记录
	 * @return
	 * @throws SQLException 
	 */
	public List<OrderRecord> getAll(int oid) throws SQLException{
		String sql="select * from order_record where oid=? order by or_date desc";
		return db.executeQuery(sql, new GlobalParamHandler(oid), this);
		
	}
	
	/**
	 * 插入订单操作记录
	 * @param orContent
	 * @param oid
	 * @return
	 * @throws SQLException
	 */
	public boolean insertRecord(String orContent,String orMan,int oid) throws SQLException{
		String sql="insert into order_record(or_content,or_man,oid) values(?,?,?)";
		return db.executeUpdate(sql, new GlobalParamHandler(orContent,orMan,oid))>0;
	}

}
